package org.uiot.process

import org.apache.flink.api.common.serialization.SimpleStringSchema
import org.apache.flink.streaming.connectors.rabbitmq.RMQSink
import org.apache.flink.streaming.connectors.rabbitmq.common.RMQConnectionConfig
import org.uiot.resource.RmqInst

trait RmqOutputTraits {

    RmqInst rmqOutput
    String sinkQueue

    RMQSink<String> getRmqSink() {

        def rmqConnectionConfig = new RMQConnectionConfig.Builder()
                .setUserName(rmqOutput.username)
                .setPassword(rmqOutput.password)
                .setVirtualHost("/")//multi-tenant
                .setHost(rmqOutput.host)
                .setPort(rmqOutput.port)
                .build()

        new RMQSink<String>(
                rmqConnectionConfig,       // config for the RabbitMQ connection
                sinkQueue,                 // name of the RabbitMQ queue to send messages to
                new SimpleStringSchema())
    }
}